package com.ye.controller;

import com.ye.domain.Comments;
import com.ye.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RefreshScope
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    @GetMapping("/getAllComments")
    public List<Comments> getAllCommentsByMusicId(@RequestParam("musicId") Integer musicId){
        return commentsService.getAllCommentsByMusicId(musicId);
    }


    //    查询指定musicId下的所有首级评论
    @GetMapping("/getFirsts")
    public List<Comments> getFirsts(@RequestParam("musicId") Long musicId){
        return commentsService.getFirsts(musicId);
    }

    //    查询当前音乐下的所有首级评论各自对应的二级评论
    @GetMapping("/getChilds")
    public List<Comments> getChilds(@RequestParam("commentsId") Long commentsId){
        return commentsService.getChilds(commentsId);
    }



    //    添加一条评论
    @GetMapping("/insertFirstComment")
    public void firstComment(@RequestParam("musicId") Long musicId,@RequestParam("content") String content,@RequestParam("userId") Long userId){
        commentsService.firstComment(musicId,content,userId);
    }

    //    添加一条回复
    @GetMapping("/reply")
    public void reply(@RequestParam("musicId") Long musicId,@RequestParam("parentId") Long parentId,@RequestParam("content") String content,@RequestParam("userId") Long userId){
        commentsService.reply(musicId,parentId,content,userId);
    }

}
